package com.fengdi.book.easy.String;

import java.util.LinkedHashMap;

public class CountAndSay {
    public String countAndSay(int n) {
        if(n == 1) return "1";

        String s1 = countAndSay(n - 1);
        StringBuilder result = new StringBuilder();
        int count = 0;
        char current = s1.charAt(0);

        for(int i = 0; i < s1.length(); i++) {
            if(current == s1.charAt(i)) {
                count++;
            }else {
                result.append(count);
                result.append(current);
                current = s1.charAt(i);
                count = 1;
            }
        }

        result.append(count);
        result.append(current);
        return result.toString();
    }

}
